using System;
using System.Collections;

namespace Composite
{
    public abstract class Entry
    {
        private string name;

        public Entry(string name)
        {
            this.name = name;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public virtual int Size
        {
            get { return 0; }
        }

        public virtual Entry add(Entry entry)
        {
            throw new Exception();
        }

        public abstract void printList(string prefix);

        public void printList()
        {
            printList("");
        }
    }

    public class File : Entry
    {
        private int size;

        public File(string name, int size)
            : base(name)
        {
            this.size = size;
        }

        public override int Size
        {
            get { return size; }
        }

        public override void printList(string prefix)
        {
            Console.WriteLine("{0}/{1} ({2})", prefix, Name, Size);
        }
    }

    public class Directory : Entry
    {
        private ArrayList directory = new ArrayList();

        public Directory(string name)
            : base(name)
        {

        }

        public override int Size
        {
            get
            {
                int size = 0;
                foreach (Entry entry in directory)
                {
                    size += entry.Size;
                }

                return size;
            }
        }

        public override Entry add(Entry entry)
        {
            directory.Add(entry);
            return this;
        }

        public override void printList(string prefix)
        {
            Console.WriteLine("{0}/{1} ({2})", prefix, Name, Size);
            foreach (Entry entry in directory)
            {
                entry.printList(prefix + "/" + Name);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Directory windows = new Directory("Windows");
            Directory system32 = new Directory("system32");
            windows.add(system32);
            windows.add(new File("desktop.ini", 923));
            windows.add(new File("TASKMAN.EXE", 15360));
            system32.add(new File("shutdown.exe", 23552));

            windows.printList();

            Console.ReadLine();
        }
    }
}

